package com.cms.cmsbackend.service;

import com.cms.cmsbackend.mapper.ArticleMapper;
import com.cms.cmsbackend.pojo.Article;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service

public class ArticleService {

    @Autowired
    private ArticleMapper articleMapper;
    public PageInfo selectByPage(int page, int size, String author, String title) {
        PageHelper.startPage(page,size);
        Example example = new Example(Article.class);
        example.createCriteria()
                .andLike("author","%" + author + "%")
                .andLike("title","%" + title +  "%");
        List<Article> articles = articleMapper.selectByExample(example);

        return new PageInfo(articles);
    }
}
